package basics;

import java.util.*;

/**
 * @author dataexa
 * @Date 2023/9/11
 * 参数测试
 */
public class ArgsTest {
    public static void main(String[] args) {

        int id = 0;
        System.out.println(id);  //0

        User user = new User();
        user.setName("1111");
        user.setEmail("111@qq.com");
        getNumberObject(user);
//        System.out.println(user.toString());

        List<String> list = new ArrayList<>();
        list.add("1");
        getNumberObject(list);
//        System.out.println(list.toString());

        String string = "1111111";
        getNumberObject(string);
//        System.out.println(string);
        Map<String, String> hashMap = new HashMap<>();
        hashMap.put("1", "2");
        getNumberObject(hashMap);
        System.out.println(hashMap);
    }


    // 值传递  (参数的副本)
    private static void getNumberObject(String user) {
        user = "sdsvcb";
    }


    // 引用传递（使用地址）
    private static void getNumberObject(Map<String, String> map) {
        map.put("key01", "value01");
    }

    private static void getNumberObject(User user) {
        user.setName("xxx");
        user.setEmail("xxx@qq.com");
    }

    private static void getNumberObject(List<String> list) {
        list.add("zzz");
        list.add("xxx");
    }


}

class User {
    public String name;
    public String email;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Override
    public String toString() {
        return "User{" + "name='" + name + '\'' + ", email='" + email + '\'' + '}' ;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        User user = (User) o;

        if (!Objects.equals(name, user.name)) return false;
        return Objects.equals(email, user.email);
    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + (email != null ? email.hashCode() : 0);
        return result;
    }
}